local joy__elai = fk.CreateSkill {

  name = "joy__elai",

  tags = { Skill.Compulsory, },

}


--
joy__elai:addEffect(fk.Death, {
  name = "joy__elai",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {"fk.MarkChanged"},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(joy__elai.name) and data.name == "@@joy__secure" and data.num < 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    if player:isWounded() then table.insert(choices, "recover") end
    local targets = table.filter(room.alive_players, function (p) return player:inMyAttackRange(p) end)
    if #targets > 0 then
      table.insert(choices, "joy__elai_damage")
    end
    if #choices == 0 then return false end
    table.insert(choices, "Cancel")
    local choice = room:askForChoice(player, choices, joy__elai.name)
    if choice == "joy__elai_damage" then
      local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#joy__elai-choose", joy__elai.name, false)
      room:damage{
        from = player,
        to = room:getPlayerById(tos[1]),
        damage = 1,
        skillName = joy__elai.name,
      }
    elseif choice == "recover" then
      room:recover { num = 1, skillName = joy__elai.name, who = player, recoverBy = player }
    end
  end,
})
--]]
return joy__elai